package com.ljh.mybatis.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ljh.mybatis.dao.DepartmentDao;
import com.ljh.mybatis.entity.Department;
import com.ljh.mybatis.service.DepartmentService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

import static com.ljh.mybatis.config.Build.build;

/**
 * (Department)表服务实现类
 *
 * @author makejava
 * @since 2020-11-09 19:03:44
 */
@Service("departmentService")
public class DepartmentServiceImpl  implements DepartmentService   {
    @Resource
    DepartmentDao departmentDao;
    //通过id查询单条数据
    @Override
    public Department queryById(Integer id) {
        Department department=departmentDao.queryById(id);
        return department;
    }
    //查询所有数据
    @Override
    public List<Department> selectAll() {
        List<Department> departmentList=departmentDao.selectAll();
        return departmentList;
    }
    //根据id删除数据
    @Override
    public boolean deleteUserById(Integer id) {
        departmentDao.deleteUserById(id);
        return true;
    }
    //根据ids删除数据
    @Override
    public boolean deleteUserByIds(Integer[] ids) {
        departmentDao.deleteUserByIds(ids);
        return false;
    }

    //新增
    @Override
    public boolean addUser(Department department) {
       departmentDao.addUser(department);
       return true;
    }
    //根据id更新
    @Override
    public boolean updateById(Department department) {
        departmentDao.updateById(department);
        return true;
    }


    //多表联合查询
    @Override
    public List<Department> selectMore() {
       List<Department> list=departmentDao.selectMore();
       return list;
    }


    //使用mybatis实现递归查询
    @Override
    public List<Department> selectD2() {
        List<Department> list=departmentDao.selectD2();
        List<Department> result=build(list);
        return result;
    }
    //使用PagerHelper完成分页查询
    @Override
    public PageInfo<Department> pageListDep(int page, int limit) {
        PageHelper.startPage(page,limit);
        List<Department> pageList=departmentDao.pageListDep();
        PageInfo<Department> objectPageInfo = new PageInfo<>(pageList);
        return objectPageInfo;
    }
    //根据条件查询，动态sql(if)
    @Override
    public List<Department> getDepCondition( Department department) {
        return departmentDao.getDepCondition(department);
    }


}